#include "utils/core-module.hpp"

using namespace cas;

int main(int argc, char *argv[])
{
    int intArg = 1;
    bool boolArg = false;
    std::string strArg = "strArg default";

    // Non-option arguments
    int nonOpt1 = 1;
    int nonOpt2 = 1;

    // Cache the initial values.  Normally one wouldn't do this,
    // but we want to demonstrate that CommandLine has changed them.
    const int intDef = intArg;
    const bool boolDef = boolArg;
    const std::string strDef = strArg;
    const int nonOpt1Def = nonOpt1;
    const int nonOpt2Def = nonOpt2;

    CommandLine cmd;
    cmd.Usage("CommandLine example program.\n"
              "This little program demonstrates how to use CommandLine.");
    cmd.AddValue("intArg", "an int argument", intArg);
    cmd.AddValue("boolArg", "a bool argument", boolArg);
    cmd.AddValue("strArg", "a string argument", strArg);
    cmd.AddNonOption("nonOpt1", "first non-option", nonOpt1);
    cmd.AddNonOption("nonOpt2", "second non-option", nonOpt2);
    cmd.Parse(argc, argv);

    // Print the source version used to build this example
    std::cout << "Program Version: ";
    cmd.PrintVersion(std::cout);
    std::cout << std::endl;

    std::cout << "Initial values:" << std::endl;

    std::cout << std::left << std::setw(10) << "intArg:"
              << intDef
              << std::endl;
    std::cout << std::setw(10) << "boolArg:"
              << std::boolalpha << boolDef << std::noboolalpha
              << std::endl;
    std::cout << std::setw(10) << "strArg:"
              << "\"" << strDef << "\""
              << std::endl;
    std::cout << std::left << std::setw(10) << "nonOpt1:"
              << nonOpt1Def
              << std::endl;
    std::cout << std::left << std::setw(10) << "nonOpt2:"
              << nonOpt2Def
              << std::endl;
    std::cout << std::endl;

    // Show final values
    std::cout << "Final values:" << std::endl;
    std::cout << std::left << std::setw(10) << "intArg:"
              << intArg
              << std::endl;
    std::cout << std::setw(10) << "boolArg:"
              << std::boolalpha << boolArg << std::noboolalpha
              << std::endl;
    std::cout << std::setw(10) << "strArg:"
              << "\"" << strArg << "\""
              << std::endl;
    std::cout << std::left << std::setw(10) << "nonOpt1:"
              << nonOpt1
              << std::endl;
    std::cout << std::left << std::setw(10) << "nonOpt2:"
              << nonOpt2
              << std::endl;
    std::cout << std::left << "Number of extra non-option arguments:"
              << cmd.GetNExtraNonOptions()
              << std::endl;

    for (std::size_t i = 0; i < cmd.GetNExtraNonOptions(); ++i)
    {
        std::cout << std::left << std::setw(10) << "extra:"
                  << "\"" << cmd.GetExtraNonOption(i) << "\""
                  << std::endl;
    }

    return 0;
}
